<template>
  <div class="cash">
    <header-bar tittle="账号绑定" sticky />

    <div class="bg"></div>

    <div class="main">
      <div class="title-box card">
        <div class="input-box u-flex-bet">
          <div class="title">收款名称</div>
          <input
            type="text"
            v-model="payee_name"
            placeholder="请输入收款名称"
          />
        </div>

        <div class="input-box u-flex-bet">
          <div class="title">收款账号</div>
          <input
            type="text"
            v-model="payee_account"
            placeholder="请输入收款账号"
          />
        </div>
      </div>

      <div class="band-box card">
        <div class="title">绑定类型</div>

        <div class="type-box">
          <div class="type u-flex-bet" @click="radio = 1">
            <div class="img-box u-flex">
              <van-image
                width="80rem"
                height="80rem"
                :src="require('@/assets/images/cash/icon_zfb@2x.png')"
              />

              <span>支付宝</span>
            </div>

            <div class="select">
              <van-image
                width="32rem"
                height="32rem"
                v-if="radio == 1"
                :src="require('@/assets/images/cash/select.png')"
              />

              <van-image
                v-if="radio != 1"
                width="32rem"
                height="32rem"
                :src="require('@/assets/images/cash/icon_unselect@2x.png')"
              />
            </div>
          </div>

          <div class="type u-flex-bet" @click="radio = 2">
            <div class="img-box u-flex">
              <van-image
                width="80rem"
                height="80rem"
                :src="require('@/assets/images/cash/icon_wx@2x.png')"
              />

              <span>微信</span>
            </div>

            <div class="select">
              <van-image
                width="32rem"
                height="32rem"
                v-if="radio == 2"
                :src="require('@/assets/images/cash/select.png')"
              />

              <van-image
                v-if="radio != 2"
                width="32rem"
                height="32rem"
                :src="require('@/assets/images/cash/icon_unselect@2x.png')"
              />
            </div>
          </div>

          <div class="type u-flex-bet" @click="radio = 3">
            <div class="img-box u-flex">
              <van-image
                width="80rem"
                height="80rem"
                :src="require('@/assets/images/cash/icon_payex@2x.png')"
              />

              <span>payex国际支付</span>
            </div>

            <div class="select">
              <van-image
                width="32rem"
                height="32rem"
                v-if="radio == 3"
                :src="require('@/assets/images/cash/select.png')"
              />

              <van-image
                v-if="radio != 3"
                width="32rem"
                height="32rem"
                :src="require('@/assets/images/cash/icon_unselect@2x.png')"
              />
            </div>
          </div>

          <div class="type u-flex-bet" @click="radio = 5">
            <div class="img-box u-flex">
              <van-image
                width="80rem"
                height="80rem"
                :src="require('@/assets/images/cash/icon_paypal@2x.png')"
              />

              <span>paypal支付</span>
            </div>

            <div class="select">
              <van-image
                width="32rem"
                height="32rem"
                v-if="radio == 5"
                :src="require('@/assets/images/cash/select.png')"
              />

              <van-image
                v-if="radio != 5"
                width="32rem"
                height="32rem"
                :src="require('@/assets/images/cash/icon_unselect@2x.png')"
              />
            </div>
          </div>
        </div>
      </div>

      <div class="tips-box u-flex">
        <span>提示：请正确填写收款人姓名和收款人账号，否则无法正常收款</span>
      </div>

      <div class="btn-box" @click="onSubmit">
        <div class="btn">保存</div>
      </div>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
import header from "@/components/header/header.vue";
import { Field } from "vant";
import {
  Button,
  Toast,
  Image as VanImage,
  Cell,
  CellGroup,
  Uploader,
  sticky,
  Form,
  Radio,
  RadioGroup,
} from "vant";
import { API_PATH } from "@/api/index.js";
import { BIND_ACCOUNT } from "@/api/api.js";
// import { Field } from 'vant';
Vue.use(Field);
Vue.use(VanImage);
Vue.use(Cell);
Vue.use(CellGroup);
Vue.use(Uploader);
Vue.use(sticky);
Vue.use(Form);
Vue.use(Radio);
Vue.use(RadioGroup);
export default {
  name: "recharge",
  components: {
    [header.name]: header,
    [Button.name]: Button,
  },
  data() {
    return {
      payee_name: "",
      payee_account: "",
      radio: "1",
      img: require("../.././assets/images/alipay.png"),
    };
  },
  created() {
    let data = this.$route.query.data;

    if (data) {
      let obj = decodeURI(data);
      let objs = JSON.parse(obj);
      this.radio = objs.type.toString();
      this.payee_name = objs.payee_name;
      this.payee_account = objs.payee_account;
    }
  },
  mounted() {},
  methods: {
    async onSubmit(values) {
      console.log("submit", values);
      const { data } = await this.$reqPost(BIND_ACCOUNT, {
        payee_name: this.payee_name,
        payee_account: this.payee_account,
        type: this.radio,
      });
      if (data.status == 0) {
        Toast.fail(data.info);
      }
      if (data.status == 1) {
        let that = this;
        Toast.success({
          message: "绑定成功!",
          onClose: function() {
            that.$router.push({ name: "walletOut" });
          },
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.cash {
  min-height: 100vh;
  background-color: #f5f5f5;

  .bg {
    height: 464rem;
    background: linear-gradient(
      180deg,
      #2f81fe 80%,
      rgba(47, 129, 254, 0) 100%
    );
  }

  .main {
    padding: 24rem;
    position: relative;

    .card {
      background-color: #fff;
      border-radius: 20rem;
    }

    .title-box {
      .input-box {
        padding: 24rem;
        border-bottom: 2rem solid #f8f8f8;

        &:last-child {
          border: none;
        }

        .title {
          font-size: 32rem;
          font-weight: bold;
          min-width: 140rem;
        }

        input {
          margin-left: 20rem;
          text-align: right;
          font-size: 32rem;
        }
      }
    }

    .band-box {
      margin-top: 24rem;
      padding: 24rem;

      .title {
        font-size: 32rem;
        font-weight: bold;
        text-align: left;
      }

      .type-box {
        .type {
          padding: 24rem 0;
          border-bottom: 2rem solid #f8f8f8;
          &:last-child {
            border: 0;
          }

          .img-box {
            span {
              margin-left: 24rem;
              font-size: 28rem;
            }
          }
        }
      }
    }

    .tips-box {
      position: relative;
      margin-top: 28rem;
      color: #999;
      width: 100%;
      height: 20rem;

      span {
        position: absolute;
        left: -50rem;
        transform: scale(0.8);
        font-size: 20rem;
      }
    }

    .btn-box {
      margin-top: 80rem;
      height: 88rem;
      line-height: 88rem;
      text-align: center;
      color: #fff;
      font-size: 32rem;
      font-weight: bold;
      border-radius: 44rem;
      box-shadow: 0px 4rem 12rem rgba(75, 150, 255, 0.3);
      background: linear-gradient(145deg, #2cb1ff 0%, #2f81fe 100%);

      .btn {
        width: 100%;
      }
    }
  }
}
</style>
